<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="/web/system/admin/include :: top"></th:block>
</head>
<body class="gray-bg">

<form class="layui-form" action="" id="form">
    <table width="95%" style="margin: 0 auto">
        <tr>
            <td width="18%" align="right"><label class="layui-form-label">项目名称：<span style="color: #ff0000">*</span></label></td>
            <td colspan="3"><input type="text" name="title" id="title" th:value="${p.title}" readonly lay-verify="required|field_len120" autocomplete="off" placeholder="项目名称" class="layui-input"></td>
        </tr>
        <tr>
            <td width="18%" align="right"><label class="layui-form-label">服务开始时间：<span style="color: red">*</span></label></td>
            <td colspan="3"><input type="text" name="start_time" id="start_time" th:value="${p.start_time}" lay-verify="required|field_len50" autocomplete="off" placeholder="服务开始时间" class="layui-input"></td>
        </tr>
        <tr>
            <td width="18%" align="right"><label class="layui-form-label">服务结束时间：<span style="color: red">*</span></label></td>
            <td colspan="3"><input type="text" name="end_time" id="end_time" th:value="${p.end_time}" lay-verify="required|field_len50" autocomplete="off" placeholder="服务结束时间" class="layui-input"></td>
        </tr>
        <tr>
            <td width="18%" align="right"><label class="layui-form-label">IP地址：<span style="color: red">*</span></label></td>
            <td colspan="3"><input type="text" name="ip_address" id="ip_address" th:value="${p.ip_address}" lay-verify="required|field_len50" autocomplete="off" placeholder="IP地址" class="layui-input"></td>
        </tr>
        <tr>
            <td width="18%" align="right"><label class="layui-form-label">Mac地址：</label></td>
            <td colspan="3"><input type="text" name="mac_address" id="mac_address" th:value="${p.mac_address}" lay-verify="field_len50" autocomplete="off" placeholder="Mac地址" class="layui-input"></td>
        </tr>
        <tr>
            <td width="18%" align="right"><label class="layui-form-label">其他限制：</label></td>
            <td colspan="3"><input type="text" name="other_limit" id="other_limit" th:value="${p.other_limit}" lay-verify="field_len50" autocomplete="off" placeholder="其他限制" class="layui-input"></td>
        </tr>
        <tr>
            <td width="18%" align="right"><label class="layui-form-label">版本号：<span style="color: red">*</span></label></td>
            <td colspan="3"><input type="text" name="version_num" id="version_num" th:value="${p.version_num}" lay-verify="required|intNumber|field_len50" autocomplete="off" placeholder="版本号" class="layui-input"></td>
        </tr>
        <tr>
            <td align="right"><label class="layui-form-label">备注：</label></td>
            <td colspan="3"><textarea name="remark" placeholder="请输入备注" class="layui-textarea" th:text="${p.remark}"></textarea></td>
        </tr>
        <tr>
            <td style="text-align: center; padding-top: 10px;" colspan="4">
                <div class="layui-form-item">
                    <input type="hidden" name="id" id="id" th:value="${p.id}" />
                    <button type="button" class="layui-btn layui-btn-sm" id="submit_button" lay-submit="" lay-filter="submit_form">保存</button>
                    <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" id="cancel">取消</button>
                </div>
            </td>
        </tr>
    </table>
</form>

<script type="text/javascript" th:src="@{/static/plugins/xadmin/lib/layui/layui.js}" charset="utf-8"></script>
<script type="text/javascript" th:src="@{/static/js/qfverify.js}"></script>
<script type="text/javascript" th:src="@{/static/js/qfAjaxReq.js}"></script>
<script type="text/javascript" th:src="@{/static/js/uploadFile.js}"></script>
<script>
    var form,layer,layedit,laydate,upload;
    layui.use(['form', 'layedit', 'laydate', 'upload'], function(){
        form = layui.form;
        layer = layui.layer;
        layedit = layui.layedit;
        laydate = layui.laydate;
        upload = layui.upload;

        $('#cancel').on('click',function (){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        })

        initDateType("start_time",false);
        initDateType("end_time",false);

        //自定义验证规则
        form.verify(form_verify);

        //监听提交
        form.on('submit(submit_form)', function(data){
            layer.msg('正在提交数据。');
            $("#submit_button").attr('disabled',true);
            $.ajax({
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: ctx+"common/authCert/update" ,//url
                data: $('#form').serialize(),
                success: function (res) {
                    if (res.success) {
                        layer.msg("数据更新成功。", {time: 2000},function(){
                            setOpenCloseParam("reload");
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }else{
                        $("#submit_button").attr('disabled',false);
                        if(res.loseSession=='loseSession'){
                            loseSession(res.msg,res.url)
                        }else{
                            layer.msg(res.msg, {time: 2000});
                        }
                    }
                },
                error : function() {
                    $("#submit_button").attr('disabled',false);
                    layer.msg("异常！");
                }
            });
            return false;
        });

    });
</script>

<th:block th:include="/web/system/admin/include :: bottom" />
</body>
</html>